import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
 * 删除员工信息
 */
public class Remove {
    public static void remove(List<Map<String, Object>> em, String instruction) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请选择你要删除信息对应的员工编号（可多选，用,分隔）");
        String id = scanner.nextLine();
        String[] split = id.split(",");
        //foreach循环删除元素会出现并发风险，通过iterator迭代器来是实现remove功能
        Iterator<Map<String, Object>> iterator = em.iterator();
        while (iterator.hasNext()) {
            Map<String, Object> next = iterator.next();
            String toString = next.get("id").toString();
            for (int i = 0; i < split.length; i++) {
                if (toString.equals(split[i])) {
                    //删除整个元素
                    iterator.remove();
                    System.out.println("删除了id为"+split[i]+"的员工");
                    break;
                }
            }
        }
    }
}

